package cn.sccl.dirms.monitor.service.impl;

import cn.sccl.common.zabbix.Zabbix;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author _minus
 * @create 2017-06-05 11:39
 */
@Service
public class HostGroupManagerImpl implements cn.sccl.dirms.monitor.service.HostGroupManager {

    @Override
    public List<Map<String,Object>> listTemplatesGroup() {
        Zabbix zabbix = Zabbix.getZabbix();

        Map<String, Object> params = new HashMap<String,Object>();
        params.put("output","extend");
        params.put("templated_hosts",true);
        params.put("selectTemplates","extend");//选择所有的模板
        Map<String, Object> result = zabbix.call("hostgroup.get",params);

        List<Map<String, Object>> mapList = (List<Map<String, Object>>) result.get("result");
        List<Map<String, Object>> reltList = new ArrayList<>();
        for (Map<String, Object> item : mapList) {
            if (!((String)item.get("name")).equals("Templates")) {
                item.put("id", item.get("groupid"));
                item.put("type", 1);
                reltList.add(item);
            }
        }
        return reltList;
    }

    @Override
    public List<Map<String,Object>> listHostgroup() {
        Zabbix zabbix = Zabbix.getZabbix();
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("output","extend");
        params.put("with_hosts_and_templates",true);
        params.put("selectTemplates","extend");//选择所有的模板
        Map<String, Object> result = zabbix.call("hostgroup.get",params);
        List<Map<String, Object>> mapList = (List<Map<String, Object>>) result.get("result");
        List<Map<String, Object>> reltList = new ArrayList<>();
        for (Map<String, Object> item : mapList) {
            if (!((String)item.get("name")).equals("Templates")) {
                item.put("id", item.get("groupid"));
                item.put("type", 1);
                reltList.add(item);
            }
        }
        return reltList;
    }
}
